import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.*;

class MyCheckBoxContainer extends MyComponentContainer {
    
    private String relation;
    
    MyCheckBoxContainer(MyFrame frame) {
        super(new JCheckBox(), frame);
        ((JCheckBox)myComponent).addMouseListener(new MouseHandler());
        ((JCheckBox)myComponent).addMouseMotionListener(new MouseDragHandler());
        ((JCheckBox)myComponent).setSelected(true);
        ((JCheckBox)myComponent).setEnabled(false);
    }
    //#########################################################################
    /**
     *  This function is used to set the field that is related to the checkBox
     */
    public void setRelation(String relation) {
        this.relation = relation;
    }
    
    //#########################################################################
    /**
     *  This function is used to get the field that is related to the checkBox
     */
    public String getRelation() {
        return relation;
    }
    //#########################################################################
    public class MouseHandler extends MouseAdapter {
        public void mouseClicked(MouseEvent m) {
            if (m.getButton() == 3) {
                setChosen(true);
                showBorder();
                handleRightClickSelection();
                MyRightClickMenu popUpMenu = new MyRightClickMenu(MyCheckBoxContainer.this,m.getX(),m.getY(),frame);
            }
            if (m.getButton()==MouseEvent.BUTTON1) {
                if (m.getClickCount()==2) {
                    //System.out.println("\n---------------->it is double yaaaaaaaaa\n");
                    JComponent eventObject =(JComponent) m.getComponent(); /* Get the component that is
                     responsable for the action */
                    MyPropertiesWindow properties = new MyPropertiesWindow(MyCheckBoxContainer.this,frame);
                    /*Createing the properties window and send the object that is
                     resposable for the event*/
                    //System.out.println("AWCH");
                } else if (m.getClickCount()==1 & m.isShiftDown()==false){
                    if (isChosen()==false) {
                        showBorder();
                        setChosen(true);
                    }
                }
            }
        }
        
        public void mousePressed(MouseEvent m) {
            frame.panel.requestFocusInWindow();
            
            if (m.getButton()==MouseEvent.BUTTON1) {
                handleSelection(m);
                frame.panel.setCursor(new Cursor(Cursor.HAND_CURSOR));
                clickToAnchorX=m.getX();
                clickToAnchorY=m.getY();
            }
        }
        
        public void mouseReleased(MouseEvent m) {
            if (m.getButton()==MouseEvent.BUTTON1) {
                frame.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
            }
            handleUndo();
        }
        
        public void mouseEntered(MouseEvent m) {
            if (isChosen()==true) {
                frame.panel.setCursor(new Cursor(Cursor.HAND_CURSOR));
            }
        }
        
        public void mouseExited(MouseEvent m) {
            if (isChosen()==true) {
                frame.panel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
            }
        }
    }
    //#########################################################################
    class MouseDragHandler extends MouseMotionAdapter {
        public void mouseDragged(MouseEvent evt) {
            handleDrag(evt);
        }
    }
}